//
//  VIZVistorView.m
//  Young-Old
//
//  Created by 位立志 on 16/4/26.
//  Copyright © 2016年 位立志. All rights reserved.
//

#import "VIZVistorView.h"


@interface VIZVistorView()

@property(nonatomic,weak)UIImageView *house;
@property(nonatomic,weak)UIImageView *circle;
@property(nonatomic,weak)UIImageView *backGround;
@property(nonatomic,weak)UILabel *tip;

@end



@implementation VIZVistorView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    
    }
    //开始动画
    [self startAnimation];
    
    return self;
}

- (void)setUI{
    
    //设置颜色
    CGFloat value = 237/255.0;
    self.backgroundColor = [UIColor colorWithRed:value green:value blue:value alpha:1];
    
    
    //登录按钮
    UIButton *loginBtn = [[UIButton alloc]init];
    [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    //按钮的背景图片进行拉伸
    UIImage *image = [UIImage imageNamed:@"common_button_white_disable"];
    CGFloat capW = image.size.width*0.5;
    CGFloat capH = image.size.height*0.5;
    
    [loginBtn setBackgroundImage:[image stretchableImageWithLeftCapWidth:capW topCapHeight:capH] forState:UIControlStateNormal];
    self.loginBtn = loginBtn;
    [loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    
    //注册按钮
    UIButton *resignBtn = [[UIButton alloc]init];
    [resignBtn setTitle:@"注册" forState:UIControlStateNormal];
    [resignBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [resignBtn setBackgroundImage:[image stretchableImageWithLeftCapWidth:capW topCapHeight:capH] forState:UIControlStateNormal];
    self.resignBtn = resignBtn;
    [resignBtn addTarget:self action:@selector(resign) forControlEvents:UIControlEventTouchUpInside];
    
    //大房子
    UIImageView *house = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    self.house = house;
    
    //圆环
    UIImageView *circle = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    self.circle = circle;
    
    //背景图
    UIImageView *backGround = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    self.backGround = backGround;
    
    //提示消息
    UILabel *tip = [[UILabel alloc]initWithText:@"您还没有登录,请登录" textColor:[UIColor lightGrayColor] fontSize:14];
    self.tip = tip;

    //添加子控件
    [self addSubview:house];
    [self addSubview:circle];
    [self addSubview:circle];
    [self addSubview:backGround];
    [self addSubview:tip];
    [self addSubview:loginBtn];
    [self addSubview:resignBtn];
    
    [self bringSubviewToFront:house];

    
    //布局
    [house makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX);
        make.centerY.equalTo(self.centerY).offset(-40);
    }];
    [circle makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX);
        make.centerY.equalTo(self.centerY).offset(-40);
    }];
    [backGround makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX);
        make.centerY.equalTo(self.centerY).offset(-40);
    }];

    [tip makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(house.bottom).offset(16);
        make.centerX.equalTo(self);
        make.height.equalTo(@40);
        make.width.equalTo(@230);
    }];
    
    [loginBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tip.left);
        make.top.equalTo(tip.bottom).offset(16);
        make.width.equalTo(@100);
    }];
    
    [resignBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(tip.right);
        make.top.equalTo(tip.bottom).offset(16);
        make.width.equalTo(@100);
    }];


    
    
    
}

////1.创建动画
//36     CABasicAnimation *anima=[CABasicAnimation animationWithKeyPath:@"transform"];
//37     //1.1设置动画执行时间
//38     anima.duration=2.0;
//39     //1.2修改属性，执行动画
//40     anima.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2+M_PI_4, 1, 1, 0)];
//41     //1.3设置动画执行完毕后不删除动画
//42     anima.removedOnCompletion=NO;
//43     //1.4设置保存动画的最新状态
//44     anima.fillMode=kCAFillModeForwards;
//45
//46     //2.添加动画到layer
//47     [self.myLayer addAnimation:anima forKey:nil];



//动画方法
- (void)startAnimation{
    
    //创建动画
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.repeatCount = MAXFLOAT;
    animation.duration = 3;
    animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(2*M_PI, 0, 0, 0)];
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    [self.circle.layer addAnimation:animation forKey:nil];
    
}


//授权回调页：http://baidu.com
//取消授权回调页：http://http://www.jianshu.com
//重置App Secret:0051c737192f61155911a503c76f180f

/**
 *  登录按钮点击方法
 */
- (void)login{
    
    NSLog(@"登录");
    
}

/**
 *  注册按钮点击方法
 */
- (void)resign{
    
    NSLog(@"注册");
    
}



@end
